const cookieObj = myGetCookie();
if (cookieObj.login === "1") {
  $("[name=login]").html("已登录");
} else {
  $("[name=login]").html("未登录");
}
//登录按钮
$('[name="login"]').click(function () {
  //跳转登录页面 同时携带当前页面的url地址
  window.location.href = `./login2.html?url=${window.location.href}`;
});
//退出登录按钮
$('[name="logout"]').click(function () {
  //先获取cookie对象
  const cookieObj = myGetCookie();
  //判断是否已经登录
  if (cookieObj.login === "1") {
    mySetCookie("login", 0, -1, "/");
    window.alert("您已经退出登录了");
  } else {
    window.alert("您还未登录，请先登录");
  }
});
//3.跳转购物车
$("[name=cart]").click(function () {
  const cookieObj = myGetCookie();
  if (cookieObj.login === "1") {
    window.location.href = "./cart2.html";
  } else {
    if (window.confirm("您还未登录，请先登录")) {
      window.location.href = `./login2.html?url=${window.location.href}`;
    }
  }
});

//点击商品分类标签
$('[name="1"]').click(function () {
  window.location.href = `./list2.html?id=${$(this).html()}`;
});
////
$(".searchTop2 button").click(function () {
  const inputVal = $(".searchTop2 input").val();
  console.log(inputVal);
  if (inputVal === "") {
    return;
  }
  //根据用户输入的信息查找相应文字
  const arr = ["食品酒水", "童装玩具", "家装建材", "奶粉尿裤"];
  //遍历数组 和输入的信息对比 能对应就跳转
  for (let i = 0; i < arr.length; i++) {
    console.log(i);
    if (arr[i] === inputVal) {
      window.location.href = `./list2.html?id=${inputVal}`;
    } else {
      alert("信息不存在");
      break;
    }
  }
});
